home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / PNGLIB06.ZIP / PNGRCB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-01  |  4.6 KB  |  203 lines

  1. /* pngrcb.c - callbacks while reading a png file
  2.  
  3.    pnglib version 0.6
  4.    For conditions of distribution and use, see copyright notice in png.h
  5.    Copyright (c) 1995 Guy Eric Schalnat, Group 42, Inc.
  6.    May 1, 1995
  7.    */
  8.  
  9. #define PNG_INTERNAL
  10. #include "png.h"
  11.  
  12. void
  13. png_read_IHDR(png_struct *png_ptr, png_info *info,
  14.    png_uint_32 width, png_uint_32 height, int bit_depth,
  15.    int color_type, int compression_type, int filter_type,
  16.    int interlace_type)
  17. {
  18.    if (!png_ptr || !info)
  19.       return;
  20.  
  21.    info->width = width;
  22.    info->height = height;
  23.    info->bit_depth = bit_depth;
  24.    info->color_type = color_type;
  25.    info->compression_type = compression_type;
  26.    info->filter_type = filter_type;
  27.    info->interlace_type = interlace_type;
  28. }
  29.  
  30. void
  31. png_read_PLTE(png_struct *png_ptr, png_info *info,
  32.    png_color *palette, int num)
  33. {
  34.    if (!png_ptr || !info)
  35.       return;
  36.  
  37.    info->palette = palette;
  38.    info->num_palette = num;
  39.    info->valid |= PNG_INFO_PLTE;
  40. }
  41.  
  42. void
  43. png_read_gAMA(png_struct *png_ptr, png_info *info, float gamma)
  44. {
  45.    if (!png_ptr || !info)
  46.       return;
  47.  
  48.    info->gamma = gamma;
  49.    info->valid |= PNG_INFO_gAMA;
  50. }
  51.  
  52. void
  53. png_read_sBIT(png_struct *png_ptr, png_info *info,
  54.    png_color_8 *sig_bit)
  55. {
  56.    if (!png_ptr || !info)
  57.       return;
  58.  
  59.    memcpy(&(info->sig_bit), sig_bit, sizeof (png_color_8));
  60.    info->valid |= PNG_INFO_sBIT;
  61. }
  62.  
  63. void
  64. png_read_cHRM(png_struct *png_ptr, png_info *info,
  65.    float white_x, float white_y, float red_x, float red_y,
  66.    float green_x, float green_y, float blue_x, float blue_y)
  67. {
  68.    if (!png_ptr || !info)
  69.       return;
  70.  
  71.    info->x_white = white_x;
  72.    info->y_white = white_y;
  73.    info->x_red = red_x;
  74.    info->y_red = red_y;
  75.    info->x_green = green_x;
  76.    info->y_green = green_y;
  77.    info->x_blue = blue_x;
  78.    info->y_blue = blue_y;
  79.    info->valid |= PNG_INFO_cHRM;
  80. }
  81.  
  82. void
  83. png_read_tRNS(png_struct *png_ptr, png_info *info,
  84.    png_byte *trans, int num_trans,   png_color_16 *trans_values)
  85. {
  86.    if (!png_ptr || !info)
  87.       return;
  88.  
  89.    if (trans)
  90.    {
  91.       info->trans = trans;
  92.    }
  93.    else
  94.    {
  95.       memcpy(&(info->trans_values), trans_values,
  96.          sizeof(png_color_16));
  97.    }
  98.    info->num_trans = num_trans;
  99.    info->valid |= PNG_INFO_tRNS;
  100. }
  101.  
  102. void
  103. png_read_bKGD(png_struct *png_ptr, png_info *info,
  104.    png_color_16 *background)
  105. {
  106.    if (!png_ptr || !info)
  107.       return;
  108.  
  109.    memcpy(&(info->background), background, sizeof(png_color_16));
  110.    info->valid |= PNG_INFO_bKGD;
  111. }
  112.  
  113. void
  114. png_read_hIST(png_struct *png_ptr, png_info *info, png_uint_16 *hist)
  115. {
  116.    if (!png_ptr || !info)
  117.       return;
  118.  
  119.    info->hist = hist;
  120.    info->valid |= PNG_INFO_hIST;
  121. }
  122.  
  123. void
  124. png_read_pHYs(png_struct *png_ptr, png_info *info,
  125.    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  126. {
  127.    if (!png_ptr || !info)
  128.       return;
  129.  
  130.    info->x_pixels_per_unit = res_x;
  131.    info->y_pixels_per_unit = res_y;
  132.    info->phys_unit_type = unit_type;
  133.    info->valid |= PNG_INFO_pHYs;
  134. }
  135.  
  136. void
  137. png_read_oFFs(png_struct *png_ptr, png_info *info,
  138.    png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
  139. {
  140.    if (!png_ptr || !info)
  141.       return;
  142.  
  143.    info->x_offset = offset_x;
  144.    info->y_offset = offset_y;
  145.    info->offset_unit_type = unit_type;
  146.    info->valid |= PNG_INFO_oFFs;
  147. }
  148.  
  149. void
  150. png_read_tIME(png_struct *png_ptr, png_info *info,
  151.    png_time *mod_time)
  152. {
  153.    if (!png_ptr || !info)
  154.       return;
  155.  
  156.    memcpy(&(info->mod_time), mod_time, sizeof (png_time));
  157.    info->valid |= PNG_INFO_tIME;
  158. }
  159.  
  160. void
  161. png_read_zTXt(png_struct *png_ptr, png_info *info,
  162.    char *key, char *text, png_uint_32 text_len, int compression)
  163. {
  164.    if (!png_ptr || !info)
  165.       return;
  166.  
  167.    if (info->max_text <= info->num_text)
  168.    {
  169.       if (info->text)
  170.       {
  171.          info->max_text = info->num_text + 16;
  172.          info->text = (png_text *)png_realloc(png_ptr,
  173.             info->text,
  174.             info->max_text * sizeof (png_text));
  175.       }
  176.       else
  177.       {
  178.          info->max_text = info->num_text + 16;
  179.          info->text = (png_text *)png_malloc(png_ptr,
  180.             info->max_text * sizeof (png_text));
  181.          info->num_text = 0;
  182.       }
  183.    }
  184.  
  185.    info->text[info->num_text].key = key;
  186.    info->text[info->num_text].text = text;
  187.    info->text[info->num_text].text_length = text_len;
  188.    info->text[info->num_text].compression = compression;
  189.    info->num_text++;
  190. }
  191.  
  192. void
  193. png_read_tEXt(png_struct *png_ptr, png_info *info,
  194.    char *key, char *text, png_uint_32 text_len)
  195. {
  196.    if (!png_ptr || !info)
  197.       return;
  198.  
  199.    png_read_zTXt(png_ptr, info, key, text, text_len, -1);
  200. }
  201.  
  202.  
  203.